<%@ page import="java.util.*,com.release.utils.*,java.text.*,java.io.*,com.release.bean.*" %>
<%

try {
		 session = request.getSession();
		//	System.out.println("user_id..main" +session.getAttribute("USER_ID"));

//	temporary removed enable this line for login, and remove if(false){
/*
  if (session.getAttribute("USER_ID") == null || !((String) session.getAttribute("SESSION_ID")).equals(session.getId())) {

				try {
					response.sendRedirect("LoginPage.jsp");
				} catch (IOException ioe) {
					ioe.printStackTrace();
				}
	
			} 
			else
	*/
	{
			
		String usergroupname = (String)session.getAttribute("USER_GROUP_NAME"); 
		//DBUtil dbutil = new DBUtil(getServletContext());
		DBUtil dbutil = new DBUtil();
		String userid = (String)session.getAttribute("USER_ID")==null?"":(String)session.getAttribute("USER_ID");
		userid ="joju.varghese@cgi.com";
	//	userid = "ronaksureshbhai.patel@cgi.com";
	//	System.out.println("userid1 :"+userid);
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>

function insertpath(indId)
	{
		//document.treelist.objectName.value=indId;
		var repostr = document.getElementById("repo").value;
		var real =indId.replace(repostr+"/","");
		document.addRelease.objectName.value=real;

	}

	function openReleasePopUp(obj)
		{
			 var AddReleaseUrl = "./AddReleaseName";
			 AddArtUrlHandle = window.open(AddReleaseUrl,"AddReleaseName","width=1000,height=700","resize=yes","maximize=yes","screenX=10","screenY=10");
		}

	function openArtfactPopUp(obj)
		{
		 var AddArtUrl = "./AddArtfactServlet";
	     AddArtUrlHandle = window.open(AddArtUrl,"AddArtfact","width=1000,height=700","resize=yes","maximize=yes","screenX=30","screenY=10");
		}
	
	function openZoomPopUp(obj){
	  var ExURL = "../FileListServlet";
	  ExHandle = window.open(ExURL,"FileList","width=1000,height=1300","resize=yes","maximize=yes","screenX=130","screenY=10");
	}

		  function trim(sString)
		  {
			sTrimmedString = "";
		   if (sString != "") {
			  var iStart = 0;
			  var iEnd = sString.length - 1;
			 // var sWhitespace = " \t\f\n\r\v";
			 var sWhitespace = "   ";


			  while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
				 iStart++;
				 if (iStart > iEnd) 
					break;
			  }

			  // If the string not just whitespace
			  if (iStart <= iEnd) {
				 while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
					iEnd--;
				 sTrimmedString = sString.substring(iStart,++iEnd);
			  }
		   }
		   return sTrimmedString;
		 }



		 	function showFiles(o)
		{
		var opassitem = document.getElementById(o);
		//alert(event.srcElement.value);
		//var imgname = "img" + o;
		//var imgAct = document.all(imgname);
		if (opassitem.style.visibility == "hidden")
		{
			opassitem.style.visibility = "visible";
			//imgAct.src = "../images/plus.gif";
		}
	/*	else
		{
			opassitem.style.visibility = "hidden";
			//imgAct.src = "../images/minus.gif";
		}*/
		}
	function hideFiles(o){
		var opassitem = document.getElementById(o);
		if (opassitem.style.visibility == "visible")
		{
			opassitem.style.visibility = "hidden";
			//imgAct.src = "../images/minus.gif";
		}
	}
		
	function unHider()
	{
	
		document.addRelease.submit();
	}
	
	

	
		



		function addRow()
		{
			document.addRelease.releaseName.value =trim(document.addRelease.releaseName.value);
			document.addRelease.dBName.value =trim(document.addRelease.dBName.value);
			document.addRelease.objectName.value =trim(document.addRelease.objectName.value);
			document.addRelease.objectType.value =trim(document.addRelease.objectType.value);
			document.addRelease.userUpdated.value =trim(document.addRelease.userUpdated.value);
			document.addRelease.dateUpdated.value =trim(document.addRelease.dateUpdated.value);

			document.addRelease.repo.value =trim(document.addRelease.repo.value);
			document.addRelease.artId.value =trim(document.addRelease.artId.value);
			//document.addRelease.dateUpdated.value =trim(document.addRelease.dateUpdated.value);
			//document.addRelease.extraIndex.value =trim(document.addRelease.extraIndex.value);
			alert("objectName :"+document.addRelease.objectName.value);
			// CR details related
			if(document.addRelease.AppScreenName != null){
			document.addRelease.AppScreenName.value =trim(document.addRelease.AppScreenName.value);
			document.addRelease.AppReportName.value =trim(document.addRelease.AppReportName.value);
			document.addRelease.Purpose.value =trim(document.addRelease.Purpose.value);
			document.addRelease.DaysTimes.value =trim(document.addRelease.DaysTimes.value);
			document.addRelease.Dependencies.value =trim(document.addRelease.Dependencies.value);
			document.addRelease.BusNotification.value =trim(document.addRelease.BusNotification.value);
			document.addRelease.Audience.value =trim(document.addRelease.Audience.value);
			document.addRelease.FAQ.value =trim(document.addRelease.FAQ.value);
			document.addRelease.Notes.value =trim(document.addRelease.Notes.value);
			document.addRelease.EscProcedure.value =trim(document.addRelease.EscProcedure.value);
			}
			//document.addRelease.CRDetails.value =trim(document.addRelease.CRDetails.value);
			document.addRelease.act.value="addRow";
			document.addRelease.submit();
			
		}

		function cl(t){
			if (t.defaultValue==t.value) 
				t.value = '';
			}

		function submitForms(obj, obj2){
		  	
					// alert("obj.value.length"+obj.value);
			
				obj.value = trim(obj.value);
	
				 if( obj2.value == 0){
					alert("Please select object type.");
					obj2.focus();
					return false;
				 }
				
				
				if (obj.value.length == 0 )
				{
					alert("Please enter Object Name.");
					obj.focus();
					return false;
				 }

				

			
				return true;
				//  document.updateRelease.submit();
				//  document.searchReleaseForm.submit();
	
				//document.displayForm.submit();
		  	
		  				//  document.MainForm.submit();
						//alert("HIIIIIII");
		} 	
		

		

				function submitForms2(obj, obj2, obj3){
		  	
					// alert("obj.value.length"+obj.value);
			
				obj.value = trim(obj.value);
	
				if (obj.value.length == 0 )
				{
					alert("Please enter Object Name.");
					obj.focus();
					return false;
				 }

				 if( obj2.value == 0){
					alert("Please select object type.");
					obj2.focus();
					return false;
				 }

				 if( obj3.value == ''){
					alert("Please enter index for new table.");
					obj3.focus();
					return false;
				}
			
				return true;
				//  document.updateRelease.submit();
				//  document.searchReleaseForm.submit();
	
				//document.displayForm.submit();
		  	
		  				//  document.MainForm.submit();
						//alert("HIIIIIII");
		} 	
		
		function checklengthtovalidate(str, formComponent){
		
			if(str.length > 250) {
				alert("Sorry, You can not enter more then 250 characters");
				formComponent.focus();
				return false;
			}
			else { 
				return true;
			}
		}

		function delRow(num)
		{
			
			document.addRelease.delNumber.value=num;
			document.addRelease.act.value="delRow";
			
			//alert(document.addRelease.delNumber.value);
			document.addRelease.submit();
		}
		function save()
		{
			
			document.addRelease.act.value="save";
			//document.addRelease.action="Save.do";
			document.addRelease.submit();
		}
		function saveandsend()
		{
			
			document.addRelease.act.value="saveandsend";
			document.addRelease.submit();
		}
	
	</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Sql Script</title>
<style type="text/css">
<!--
body {
	background-image: url(../images/bg/pagebg.gif);
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style2 {font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href="joju.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style4 {color: #FFFFFF}
-->
</style>
</head>

<body onload="MM_preloadImages('../images/menu2_01.jpg','../images/menu2_02.jpg','../images/menu2_03.jpg','../images/menu2_04.jpg','../images/menu2_05.jpg','../images/menu2_06.jpg','../images/menu2_07.jpg ','../images/menu2_08.jpg')">
<form name="addRelease" method="post"  >
<center>
  <table id="Table_01" width="1002" height="778" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td height="101" align="left" valign="top"><img src="../images/index_01.jpg" width="1002" height="101" alt="" /></td>
    </tr>
   <tr>
      <td height="46" align="left" valign="top"><table id="Table_3" width="1002" height="46" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><a href="newtree.jsp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image22','','../images/menu2_01.jpg',1)"><img src="../images/menu_01.jpg" alt="home" name="Image22" width="82" height="46" border="0" id="Image22" /></a></td>
            <td><a href="Data.jsp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image23','','../images/menu2_02.jpg',1)"><img src="../images/menu_02.jpg" alt="tracker" name="Image23" width="83" height="46" border="0" id="Image23" /></a></td>
            <td><a href="ReleaseReport.jsp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image24','','../images/menu2_03.jpg',1)"><img src="../images/menu_03.jpg" alt="documents" name="Image24" width="83" height="46" border="0" id="Image24" /></a></td>
            <td><a href="ReleaseReport.jsp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image27','','../images/menu2_06.jpg',1)"><img src="../images/menu_06.jpg" alt="File Release" name="Image27" width="83" height="46" border="0" id="Image27" /></a></td>   
			<td><a href="ReleaseLog.jsp" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image28','','../images/menu2_07.jpg ',1)"><img src="../images/menu_07.jpg" alt="wiki" name="Image28" width="83" height="46" border="0" id="Image28" /></a></td>
            <td><a href="buldandtest.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image29','','../images/menu2_08.jpg',1)"><img src="../images/menu_08.jpg" alt="build and test" name="Image29" width="84" height="46" border="0" id="Image29" /></a></td>
            <td><img src="../images/menu_09.jpg" width="333" height="46" alt="" /></td>
            <td><img src="../images/menu_10.jpg" width="5" height="46" alt="" /></td>
          </tr>
      </table></td>
    </tr>
    <tr>
      <td height="631" align="left" valign="top"><table id="Table_" width="1002" height="595" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="2" bgcolor="#A1C0DF"><img src="../images/content_01.jpg" width="226" height="1" alt="" /></td>
            <td><img src="../images/content_02.jpg" width="776" height="1" alt="" /></td>
          </tr>
          <tr>
            <td height="574" valign="top" bgcolor="#A1C0DF">&nbsp;</td>
            <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="835" colspan="5" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="3%">&nbsp;</td>
                      <td width="97%">&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td><table id="Table_2" width="736" height="251" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                          <td width="11"><img src="../images/login_01.jpg" width="11" height="11" alt="" /></td>
                          <td width="713" background="../images/login_02.jpg"><img src="../images/login_02.jpg" width="384" height="11" alt="" /></td>
                          <td width="12"><img src="../images/login_03.jpg" width="12" height="11" alt="" /></td>
                        </tr>
                        <tr>
                          <td background="../images/login_02.jpg"><img src="../images/login_04.jpg" width="11" height="224" alt="" /></td>
                          <td align="left" valign="top" background="../images/bg/loginbg.jpg">
							<input type=hidden name="act" value="" >
		<input type=hidden name="delNumber" value="" >
		<%
			String act =(String) request.getParameter("act");
			boolean sendmailfailflag=false;
			boolean saveflag=false;
			Vector allRel=null;
			Vector tempVector= new Vector();
			Vector ContactPersonVector = new Vector();
			ReleaseVO tempVo = null;
			java.text.SimpleDateFormat jsformatter =  new java.text.SimpleDateFormat("d MMM yyyy");
			String todate = jsformatter.format(new java.util.Date());
			String relname = (String)request.getParameter("releaseName")==null?"":request.getParameter("releaseName");
			//String extraIndex = request.getParameter("extraIndex")==null?"":request.getParameter("extraIndex");
			String extraIndex =new String ("NOTSET");
			String objTypeforIndx = request.getParameter("objectType")==null?"":request.getParameter("objectType");
			String dbNameforIndx = request.getParameter("dBName")==null?"":request.getParameter("dBName");
			String relNameforIndx = request.getParameter("releaseName")==null?"":request.getParameter("releaseName");
			String contactPerson = request.getParameter("contactPerson")==null?"":request.getParameter("contactPerson");

			if(session.getAttribute("CONTACTPERSONVECTOR")!=null){
				ContactPersonVector = (Vector)session.getAttribute("CONTACTPERSONVECTOR");
			}

			if(contactPerson!=null && !(contactPerson.equals(""))){
				
				if(!(ContactPersonVector.contains(contactPerson))){
					ContactPersonVector.add(contactPerson);
				}

				session.removeAttribute("CONTACTPERSONVECTOR");
				session.setAttribute("CONTACTPERSONVECTOR", ContactPersonVector	);
			}

			boolean extraIndxFlag = false;	
			boolean ManadatoryCRFlag = false;

			if(objTypeforIndx.equals("New Table") && dbutil.checkForIndex(dbNameforIndx)){
				extraIndxFlag = true;
			}

			if(dbutil.checkForCRDetail(objTypeforIndx)){
				ManadatoryCRFlag = true;			
			}


			if( act == null )
			{
				
			//	System.out.println("ACT  Null");
			//	System.out.println("relname1:"+relname);
				allRel = dbutil.getAllRelease(relname);
				session.removeAttribute("allRelVector");
				session.setAttribute("allRelVector",allRel);

				

			}
			else if("addRow".equals(act))
			{
				allRel =(Vector) session.getAttribute("allRelVector");
				
				if((Vector) session.getAttribute("temVector")== null)
				{
					System.out.println("Its null for addRow******* ------------------------> :");
		//			System.out.println("Its null"+(Vector) session.getAttribute("temVector"));
					tempVo = new ReleaseVO();
					tempVo.setReleaseName((String)request.getParameter("releaseName"));
					tempVo.setDBName((String)request.getParameter("dBName"));
					String checkstr = (String)request.getParameter("objectName");
		//			System.out.println("check str >>>>>>>"+checkstr);
					tempVo.setObjName(dbutil.RemoveWhiteSpace(checkstr));
		//			System.out.println("check str >>>>>>>"+dbutil.RemoveWhiteSpace(checkstr));
					tempVo.setObjType((String)request.getParameter("objectType"));
					tempVo.setDateUpdated((String)request.getParameter("dateUpdated"));
				//	tempVo.setUserUpdated((String)request.getParameter("userUpdated"));
					tempVo.setUserUpdated(userid);
					tempVo.setContactPerson(contactPerson);		
					tempVo.setSqLQuery((String)request.getParameter("sqlquery"));
					tempVo.setArtfactID((String)request.getParameter("artId"));
					tempVo.setSvnRepo((String)request.getParameter("repo"));


					System.out.println( "#############sqlqurty from request :"+request.getParameter("sqlquery"));

					/// CR details.
					tempVo.setAppScreenName((String)request.getParameter("AppScreenName")==null?"":request.getParameter("AppScreenName"));
						tempVo.setAppReportName((String)request.getParameter("AppReportName")==null?"":request.getParameter("AppReportName"));
						tempVo.setPurpose((String)request.getParameter("Purpose")==null?"":request.getParameter("Purpose"));
						tempVo.setDaysTimes((String)request.getParameter("DaysTimes")==null?"":request.getParameter("DaysTimes"));
						tempVo.setDependencies((String)request.getParameter("Dependencies")==null?"":request.getParameter("Dependencies"));
						tempVo.setBusNotification((String)request.getParameter("BusNotification")==null?"":request.getParameter("BusNotification"));
						tempVo.setAudience((String)request.getParameter("Audience")==null?"":request.getParameter("Audience"));
						tempVo.setFAQ((String)request.getParameter("FAQ")==null?"":request.getParameter("FAQ"));
						tempVo.setNotes((String)request.getParameter("Notes")==null?"":request.getParameter("Notes"));
						tempVo.setEscProcedure((String)request.getParameter("EscProcedure")==null?"":request.getParameter("EscProcedure"));


					
					allRel = dbutil.getAllRelease(tempVo.getReleaseName());
					if( dbutil.validVo(allRel,tempVo))	
					{
				//		System.out.println("::Int ITS VALID");
						tempVector.add(tempVo);
						session.removeAttribute("temVector");
						session.setAttribute("temVector",tempVector);

						System.out.println( "------------------------------> 2:");
						tempVo = null;
					}
					else
					{
					%>
						<script>
						alert("This Object already exists for selected release, Can not add same object twice !!");
						</script>
					
					<%	//  System.out.println("::Int ITS not VALID");

					}
				
					String checkforextraindex = request.getParameter("extraIndex")==null?"":request.getParameter("extraIndex");
					checkforextraindex = checkforextraindex.trim();
					
					if(!(checkforextraindex.equals("") || checkforextraindex.equals("NOTSET"))){
						tempVo = new ReleaseVO();
						tempVo.setReleaseName((String)request.getParameter("releaseName"));
						tempVo.setDBName((String)request.getParameter("dBName"));
						checkstr = (String)request.getParameter("extraIndex");
						System.out.println("check str >>>>>>>"+checkstr);
						tempVo.setObjName(dbutil.RemoveWhiteSpace(checkstr));
				//		System.out.println("check str >>>>>>>"+dbutil.RemoveWhiteSpace(checkstr));
						tempVo.setObjType("New Index");
						tempVo.setDateUpdated((String)request.getParameter("dateUpdated"));
					//	tempVo.setUserUpdated((String)request.getParameter("userUpdated"));
						tempVo.setUserUpdated(userid);
						tempVo.setContactPerson(contactPerson);		
						tempVo.setSqLQuery((String)request.getParameter("sqlquery"));
						tempVo.setArtfactID((String)request.getParameter("artId"));

					//  CR Details
					
						tempVo.setAppScreenName((String)request.getParameter("AppScreenName")==null?"":request.getParameter("AppScreenName"));
						tempVo.setAppReportName((String)request.getParameter("AppReportName")==null?"":request.getParameter("AppReportName"));
						tempVo.setPurpose((String)request.getParameter("Purpose")==null?"":request.getParameter("Purpose"));
						tempVo.setDaysTimes((String)request.getParameter("DaysTimes")==null?"":request.getParameter("DaysTimes"));
						tempVo.setDependencies((String)request.getParameter("Dependencies")==null?"":request.getParameter("Dependencies"));
						tempVo.setBusNotification((String)request.getParameter("BusNotification")==null?"":request.getParameter("BusNotification"));
						tempVo.setAudience((String)request.getParameter("Audience")==null?"":request.getParameter("Audience"));
						tempVo.setFAQ((String)request.getParameter("FAQ")==null?"":request.getParameter("FAQ"));
						tempVo.setNotes((String)request.getParameter("Notes")==null?"":request.getParameter("Notes"));
						tempVo.setEscProcedure((String)request.getParameter("EscProcedure")==null?"":request.getParameter("EscProcedure"));


						
						allRel = dbutil.getAllRelease(tempVo.getReleaseName());
					
			//			System.out.println("::Int ITS VALID");
						if( dbutil.validVo(allRel,tempVo))	
						{
						tempVector.add(tempVo);
						session.removeAttribute("temVector");
						session.setAttribute("temVector",tempVector);
						tempVo = null;
						}else{
						%>
						<script>
						alert("Index already entered by someone for selected release, So No need to add again. You can proceed.. Thanks");
						</script>
					
						<%	//  System.out.println("::Int ITS not VALID");
						
						}				
					}

					
				}
				else
				{
				//	System.out.println("Its NOT null"+(Vector) session.getAttribute("temVector"));
					tempVo = new ReleaseVO();
					tempVector = (Vector) session.getAttribute("temVector");
					tempVo.setReleaseName((String)request.getParameter("releaseName"));
					tempVo.setDBName((String)request.getParameter("dBName"));
					tempVo.setObjName(dbutil.RemoveWhiteSpace((String)request.getParameter("objectName")));
					tempVo.setObjType((String)request.getParameter("objectType"));
					tempVo.setDateUpdated((String)request.getParameter("dateUpdated"));
				//	tempVo.setUserUpdated((String)request.getParameter("userUpdated"));
					tempVo.setUserUpdated(userid);
					tempVo.setContactPerson(contactPerson);		
					tempVo.setSqLQuery((String)request.getParameter("sqlquery"));
					tempVo.setArtfactID((String)request.getParameter("artId"));

					// CR Details

					tempVo.setAppScreenName((String)request.getParameter("AppScreenName")==null?"":request.getParameter("AppScreenName"));
					tempVo.setAppReportName((String)request.getParameter("AppReportName")==null?"":request.getParameter("AppReportName"));
					tempVo.setPurpose((String)request.getParameter("Purpose")==null?"":request.getParameter("Purpose"));
					tempVo.setDaysTimes((String)request.getParameter("DaysTimes")==null?"":request.getParameter("DaysTimes"));
					tempVo.setDependencies((String)request.getParameter("Dependencies")==null?"":request.getParameter("Dependencies"));
				    tempVo.setBusNotification((String)request.getParameter("BusNotification")==null?"":request.getParameter("BusNotification"));
					tempVo.setAudience((String)request.getParameter("Audience")==null?"":request.getParameter("Audience"));
					tempVo.setFAQ((String)request.getParameter("FAQ")==null?"":request.getParameter("FAQ"));
					tempVo.setNotes((String)request.getParameter("Notes")==null?"":request.getParameter("Notes"));
					tempVo.setEscProcedure((String)request.getParameter("EscProcedure")==null?"":request.getParameter("EscProcedure"));




					allRel = dbutil.getAllRelease(tempVo.getReleaseName());
					
					if(dbutil.validVo(tempVector,tempVo) && dbutil.validVo(allRel,tempVo))
					{
				//		System.out.println("ITS VALID");
						tempVector.add(tempVo);
						session.removeAttribute("temVector");
						session.setAttribute("temVector",tempVector);
						tempVo = null;
					}
					else
					{
					%>
						<script>
						alert("This Object already exists for selected release, Can not add same object twice !!");
						</script>

					<%
				//		System.out.println("ITS not VALID");
					}


					String checkforextraindex = request.getParameter("extraIndex")==null?"":request.getParameter("extraIndex");
					checkforextraindex = checkforextraindex.trim();
					
					if(!(checkforextraindex.equals("") || checkforextraindex.equals("NOTSET"))){
						tempVo = new ReleaseVO();
						tempVo.setReleaseName((String)request.getParameter("releaseName"));
						tempVo.setDBName((String)request.getParameter("dBName"));
						String checkstr = (String)request.getParameter("extraIndex");
				//		System.out.println("check str >>>>>>>"+checkstr);
						tempVo.setObjName(dbutil.RemoveWhiteSpace(checkstr));
				//		System.out.println("check str >>>>>>>"+dbutil.RemoveWhiteSpace(checkstr));
						tempVo.setObjType("New Index");
						tempVo.setDateUpdated((String)request.getParameter("dateUpdated"));
					//	tempVo.setUserUpdated((String)request.getParameter("userUpdated"));
						tempVo.setUserUpdated(userid);
						tempVo.setContactPerson(contactPerson);							
						tempVo.setSqLQuery((String)request.getParameter("sqlquery"));
						tempVo.setArtfactID((String)request.getParameter("artId"));
					
						// CR details

						tempVo.setAppScreenName((String)request.getParameter("AppScreenName")==null?"":request.getParameter("AppScreenName"));
						tempVo.setAppReportName((String)request.getParameter("AppReportName")==null?"":request.getParameter("AppReportName"));
						tempVo.setPurpose((String)request.getParameter("Purpose")==null?"":request.getParameter("Purpose"));
						tempVo.setDaysTimes((String)request.getParameter("DaysTimes")==null?"":request.getParameter("DaysTimes"));
						tempVo.setDependencies((String)request.getParameter("Dependencies")==null?"":request.getParameter("Dependencies"));
						tempVo.setBusNotification((String)request.getParameter("BusNotification")==null?"":request.getParameter("BusNotification"));
						tempVo.setAudience((String)request.getParameter("Audience")==null?"":request.getParameter("Audience"));
						tempVo.setFAQ((String)request.getParameter("FAQ")==null?"":request.getParameter("FAQ"));
						tempVo.setNotes((String)request.getParameter("Notes")==null?"":request.getParameter("Notes"));
						tempVo.setEscProcedure((String)request.getParameter("EscProcedure")==null?"":request.getParameter("EscProcedure"));



						allRel = dbutil.getAllRelease(tempVo.getReleaseName());
					
				//		System.out.println("::Int ITS VALID");
						if(dbutil.validVo(tempVector,tempVo) && dbutil.validVo(allRel,tempVo))
						{
						tempVector.add(tempVo);
						session.removeAttribute("temVector");
						session.setAttribute("temVector",tempVector);
						tempVo = null;
						}else{
							
						%>
						<script>
						alert("Index already entered by someone for selected release, So No need to add again. You can proceed.. Thanks");
						</script>
						<%	//  System.out.println("::Int ITS not VALID");
						
						}
										
					}

				}

			}
			else if("delRow".equals(act))
			{
				String delNo = (String) request.getParameter("delNumber");
				
				if(delNo != null)
				{
					int deleteNum = Integer.parseInt(delNo);
				
					tempVector =(Vector) session.getAttribute("temVector");
					if(tempVector != null && tempVector.size()>0){
					tempVector.remove(deleteNum);
					session.removeAttribute("temVector");
					session.setAttribute("temVector",tempVector);
					}

				}
			}
			else if("save".equals(act))
			{
			//		System.out.println("^^^^^^^^^^^^^^^^^^^^^^");
					tempVector =(Vector) session.getAttribute("temVector");
					if(tempVector != null && tempVector.size()>0){

						System.out.println("tempVector is not null >>>>>>>");
						dbutil.saveRelease(tempVector);
				//		dbutil.sendEmailForIQChanges(tempVector);
						session.removeAttribute("temVector");
				//		System.out.println("relname2"+relname);
						 allRel = dbutil.getAllRelease(relname);
						session.removeAttribute("allRelVector");
						session.setAttribute("allRelVector",allRel);
					
					}
					else
					{
						System.out.println("tempVector is  null >>>>>>>");
						
				
					}


			}
				else if("saveandsend".equals(act))
			{
			//	System.out.println("save and send");
				String sender ="";
				String mailserver="";
				String header ="";
				String extraEmail = (request.getParameter("extraEmail")==null || request.getParameter("extraEmail").trim().equals(""))?"":request.getParameter("extraEmail");
			//	System.out.println("userid2 :"+userid);
			//	extraEmail = extraEmail.trim().equals{""}?userid:extraemail;
				 try {
				//File propfile = new File(System.getProperty("tracker.properties.home")+"/"+"STtracker.properties");
					Properties property = new Properties();
					//File propfile = new File(getServletContext().getInitParameter("tracker.properties.home")+"/"+"STtracker.properties");
					File propfile = new File("STtracker.properties");
					InputStream in = new FileInputStream(propfile);
					property.load(in);
					sender = property.getProperty("RelMailSender")==null?"raman.kapil@db.com":property.getProperty("RelMailSender");
			//		System.out.println("sender " +  sender);
					mailserver = property.getProperty("MailServer");
					header= property.getProperty("AddRelHeader")==null?"@@ Added New Database Object/s for Release @@":property.getProperty("AddRelHeader");
			//		System.out.println("RelHeader " +  header);

					MailClass mailclass= new MailClass(mailserver);
					StringBuffer content = new StringBuffer();
					//String sender;
		
					
					ArrayList maillist = new ArrayList();
					maillist=dbutil.getRelMailList();

					extraEmail = extraEmail.trim();
					StringTokenizer st = new StringTokenizer(extraEmail,",");
					int totaltoken = st.countTokens();
					
					int size = maillist.size(); 	
					String receive[] = new String[size+totaltoken+1];
			//		System.out.println("size" + size);
					receive[0] = userid;
					int j=0;
					for(int i=0;i<size;i++)
					{
						MailListVO maillistvo = (MailListVO) maillist.get(i);
						receive[i+1]=maillistvo.getEmail();
			//			System.out.println("rec " + receive[i]);
						j = i+1;
					}
			//		System.out.println("check 1 >");
					while(st.hasMoreElements()){
			//			System.out.println("check 1.1 >");
						receive[++j] = st.nextToken();
			//			System.out.println("check 1.2 >");
					}
			//		System.out.println("check 2 >");
					content.append("The following database objects has been added for Release. \t\t\t\t\t\t\t");
					content.append("\n\n\n");
					tempVector =(Vector) session.getAttribute("temVector");
					if(tempVector != null )
					{
						for(int i=0;i<tempVector.size();i++)
						{
							ReleaseVO relvo =(ReleaseVO) tempVector.elementAt(i);
							content.append("\n"+(i+1)+"\tRelease Name : ");
							content.append(relvo.getReleaseName());
							content.append("\n\tDB Name : ");
							content.append(relvo.getDBName());
							content.append("\n\tObject Name : ");
							content.append(relvo.getObjName());
							content.append("\n\tObject Type : ");
							content.append(relvo.getObjType());
							content.append("\n\tUser : ");
							content.append(relvo.getUserUpdated());

							content.append("\n\n\n");


						}

					}
					

					content.append("-------------------------------------------------------------------------------------------------------------------");
					content.append("\n\n");
					content.append("System generated mail, DO NOT REPLY.");
					content.append("\nKindly contact Raman Kapil (raman.kapil@db.com) for more detail or any information.");
					
					dbutil.saveArtfact(tempVector);
					dbutil.sendEmailForIQChanges(tempVector);
					session.removeAttribute("temVector");


			//		System.out.println("relname3"+relname);
					allRel = dbutil.getAllRelease(relname);
					session.removeAttribute("allRelVector");
					session.setAttribute("allRelVector",allRel);
					
					saveflag=true;
				%>
					
			<!--	<table width="750">		
					<tr>
					<td class='smalltext'><font color='red'>Saved Successfully </font></td>
					<td class='smalltext'><a href="mainpage.jsp" > Back to Main Page</a></td>
					</tr>
					 
					</table>
			-->
				<%
					

					//mailclass.postMail(receive,header,content.toString(),sender);
					

				%>
								
				<!--	
				<table width="750">		
				<td class='smalltext'><font color='red'>Mail Sent Successfully </font></td>
				</table>
				-->
					

				<%		
					sendmailfailflag = false;
				 }
				catch(Exception e)
				{
					System.out.println("Exception while sending mail :"+e);
					sendmailfailflag = true;
					
				%>	

				<!--
					<table width="750">		
	
						<td class='smalltext'><font color='red'>Could not connect to SMTP host. Sending failed.</font></td>
					</table>
				-->	
				
					
				<%	

				}
			}


			boolean releaseExecutionFlag = false;
			releaseExecutionFlag = dbutil.checkUserRightForRelease(userid);

		%>
	
						
						<table cellspacing="0" cellpadding="0" width="95%" 
                          border="0">
                            <tbody>
                              <tr class="style2">
                                <td class="marginscontact"><span class="contentbold1">Release Object- Basic Details<br />
                                  <br />
                                </span></td>
                                <td class="marginscontact">&nbsp;</td>
                                <td class="marginscontact">&nbsp;</td>
                              </tr>
                              <tr class="style2">
                                <td class="marginscontact" width="44%"><div align="right"><span class="normalcontent"><span class="content">Release Name</span> <span 
                              class="photo_name">:</span></span></div></td>
                                <td class="marginscontact" width="3%">&nbsp;</td>
                                <td class="marginscontact" width="53%">
								
								<select name=releaseName  >
								
													
								<% 															
									Vector relNameVector = dbutil.getReleaseName(userid);
									for(int i=0;i<relNameVector.size();i++)
									{
										ReleaseVO relbean =(ReleaseVO)relNameVector.elementAt(i); 
								%>
	
										<option value= '<%=	relbean.getReleaseName()%>' 									<%=relNameforIndx.equals(relbean.getReleaseName())?"selected":""%>	
										>
										<%= relbean.getReleaseName()%> 
										</option>
					
								<%	}
								%>
								</select>
									<img id="help3" src="../images/add_obj.gif" border="0" width="12" height="15" onMouseover="javascript:showFiles('SelectViewHelp3');" onMouseout="javascript:hideFiles('SelectViewHelp3');" onClick ="openReleasePopUp(this)">
							        <div id="SelectViewHelp3" style="position:absolute; left:event.x; top:event.y; visibility: hidden; BORDER:#666666 1px solid;background-color: #efefef;width:300px;padding:5px;" onMouseover="javascript:showFiles('SelectViewHelp3');" onMouseout="javascript:hideFiles('SelectViewHelp3');">
							        <br>By clicking on  plus sign you can add new Releasename.  
							      </div>
								</td>
                              </tr>

							   <tr class="style2">
                                <td class="marginscontact" width="44%"><div align="right"><span class="normalcontent"><span class="content">artifact ID</span> <span 
                              class="photo_name">:</span></span></div></td>
                                <td class="marginscontact" width="3%">&nbsp;</td>
                                <td class="marginscontact" width="53%">
								
								<select name=artId   >
								
													
								<% 															
									Vector artVector = dbutil.getArtfactIDs();
									for(int i=0;i<artVector.size();i++)
									{
										ArtfactBean artbean =(ArtfactBean)artVector.elementAt(i); 
								%>
	
										<option value= '<%=	artbean.getId()%>'>
										<%= artbean.getId()%> 
										</option>
					
								<%	}
								%>
								</select>

								<img id="help3" src="../images/add_obj.gif" border="0" width="12" height="15" onMouseover="javascript:showFiles('SelectViewHelp3');" onMouseout="javascript:hideFiles('SelectViewHelp3');"  onClick ="openArtfactPopUp(this)">
							        <div id="SelectViewHelp3" style="position:absolute; left:event.x; top:event.y; visibility: hidden; BORDER:#666666 1px solid;background-color: #efefef;width:300px;padding:5px;" onMouseover="javascript:showFiles('SelectViewHelp3');" onMouseout="javascript:hideFiles('SelectViewHelp3');">
							        <br>By clicking on  plus sign you can add new artfactID.  
							      </div> 
								
								</td>
                              </tr>
								

								  <tr class="style2">
                                <td class="marginscontact" width="44%"><div align="right"><span class="normalcontent"><span class="content">SvnRepo</span> <span 
                              class="photo_name">:</span></span></div></td>
                                <td class="marginscontact" width="3%">&nbsp;</td>
                                <td class="marginscontact" width="53%">
								
									 <select name="repo" size="1" id="repo">
                                 <% 
									ArrayList  branchlist = dbutil.getBranchlist();
									Iterator itr = branchlist.iterator(); 
									while(itr.hasNext()) {
									FileList fileobj = (FileList)itr.next(); 
									%>				
									<option value= '<%=	fileobj.getPath()%>'>
									<%= fileobj.getName()%> 
									</option>
									
									<%	} %>

                                </select>
								
								</td>
                              </tr>
                              <tr class="style2">
                                <td class="marginscontact"><div align="right"><span class="content">DB Name</span> <span 
                              class="mandatory">:</span></div></td>
                                <td class="marginscontact">&nbsp;</td>
                                <td class="marginscontact">
								
									<select name=dBName >
							<% 
								Vector dbVector = dbutil.getDbNameVO();
								for(int i=0;i<dbVector.size();i++)
								{
									DbNameVo dbvo =(DbNameVo)dbVector.elementAt(i); 
							%>

									<option value= '<%=	dbvo.getDBName()%>'  
									
										<%// = tempVo == null? "" :(tempVo.getDBName().equals(dbvo.getDBName()) ? "selected":"" )%>
										<%=dbNameforIndx.equals(dbvo.getDBName())?"selected":"" %>
									>
										<%= dbvo.getDBName()%> 
									</option>
				
							<%	}
							%>
							</select>
							&nbsp&nbsp
							<img id="help1" src="../images/help.jpg" border="0" width="12" height="15" onMouseover="javascript:showFiles('SelectViewHelp1');" onMouseout="javascript:hideFiles('SelectViewHelp1');">
					        <div id="SelectViewHelp1" style="position:absolute; left:event.x; top:event.y; visibility: hidden; BORDER:#666666 1px solid;background-color: #efefef;width:300px;padding:5px;" onMouseover="javascript:showFiles('SelectViewHelp1');" onMouseout="javascript:hideFiles('SelectViewHelp1');">
							        <br>Use has to select the Database name from the list. Select the database in which Object belongs. Ex if sproc belongs to 'intra' database then select intra here. Ex. if alter statement going to modify table of 'archive' database then select archive here.
					        </div>
								
								</td>
                              </tr>
                              <tr class="style2">
                                <td class="marginscontact"><div align="right"><span class="content">Object's Type</span>:</div></td>
                                <td class="marginscontact">&nbsp;</td>
                                <td class="marginscontact">
								
								<select name="objectType" id="objectType" >
										<option value='0' >Select Object Type</option>
										<% 
											Vector objType = dbutil.getObjTypeVO();
											
											if(objType!=null && objType.size()>0){
											for(int i=0;i<objType.size();i++)
											{
												ObjectTypeVO objvo =(ObjectTypeVO)objType.elementAt(i); 
										%>

												<option value= '<%=objvo.getObjType()%>' 
												<%//= tempVo == null?(objTypeforIndx.equals(objvo.getObjType())? "selected":"")
												//	: ( tempVo.getObjType().equals(objvo.getObjType())? "selected" :"")
													%>
												<%=objTypeforIndx.equals(objvo.getObjType())?"selected":"" %>	
													
													> 
													<%= objvo.getObjType()%> </option>
							
										<%	} }
										%>
							</select>
								
								
								</td>
                              </tr>
                              <tr class="style2">
                                <td class="marginscontact"><div align="right">Object Name:</div></td>
                                <td class="marginscontact">&nbsp;</td>
                                <td class="marginscontact">
								<input type="text" class="box" id ="objectName" name="objectName" size="31" value='<%= tempVo == null?"": tempVo.getObjName()%>'>
								</td><td><img src="../images/checkout.gif" width="16" height="16" onClick ="openZoomPopUp(this)" /></td>
                              </tr>
                              <tr>
                                <td valign="top" class="marginscontact"><div align="right">User Updated :</div></td>
                                <td valign="top" class="marginscontact">&nbsp;</td>
                                <td class="marginscontact" valign="center">
									<input type="text" class="box" name="userUpdated" id ="userUpdated" size="31" value=<%=userid%> <% out.println("disabled"); %>
									> 
							  </td>
                              </tr>
                              <tr>
                                <td valign="top" class="marginscontact"><div align="right">Contact Person's Email:</div></td>
                                <td valign="top" class="marginscontact">&nbsp;</td>
                                <td class="marginscontact" valign="center">
								<input type="text"  class="box" name="contactPerson" id="contactPerson" size="31" value='<%= tempVo == null?"": tempVo.getContactPerson()%>'> 
								<img id="help4" src="../images/help.jpg" border="0" width="12" height="15" onMouseover="javascript:showFiles('SelectViewHelp4');" onMouseout="javascript:hideFiles('SelectViewHelp4');">
								<div id="SelectViewHelp4" style="position:absolute; left:event.x; top:event.y; visibility: hidden; BORDER:#666666 1px solid;background-color: #efefef;width:300px;padding:5px;" onMouseover="javascript:showFiles('SelectViewHelp4');" onMouseout="javascript:hideFiles('SelectViewHelp4');">
							        <br>Please enter the Email-Id of contact person, If he/she is different then Logged in User. 
									<br>Kindly enter only single Email-Id here. You can inform other users by entering more Email-Ids below in Send Email box,  to send email.
								</div>
								</td>
                              </tr>
							  <input type=hidden name=dateUpdated value='<%= tempVo == null? todate: tempVo.getDateUpdated()%>' > 
                              <tr>
                                <td valign="top" class="content">&nbsp;</td>
                                <td valign="top" class="marginscontact">&nbsp;</td>
                                <td class="marginscontact" valign="center">
								<input type=button class=whitebutton name=addButton value=Add  onclick='return addRow()'>
									&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<font  color="#FF6600"> * - Mandatory Field</font>
								
								</td>
                              </tr>
                            </tbody>
                          </table></td>
                          <td background="../images/login_06.jpg"><img src="../images/login_06.jpg" width="12" height="224" alt="" /></td>
                        </tr>
                        <tr>
                          <td><img src="../images/login_07.jpg" width="11" height="16" alt="" /></td>
                          <td background="../images/login_08.jpg" bgcolor="#F3F7FA"><img src="../images/login_08.jpg" width="384" height="16" alt="" /></td>
                          <td><img src="../images/login_09.jpg" width="12" height="16" alt="" /></td>
                        </tr>
                      </table></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>
					  	<% 
						tempVector =(Vector) session.getAttribute("temVector");
						if( tempVector != null && tempVector.size() >0)
						{
						 %>
					  <table width="100%" border="1" cellspacing="1" cellpadding="1">
								<tr bgcolor="#ADDFFF">
								  <td width="14%" class="contentbold1">Release Name </td>
								  <td width="11%" class="contentbold1">DB Name</td>
								  <td width="21%" class="contentbold1">Object Name / SQL Query</td>
								  <td width="13%" class="contentbold1">Object Type</td>
								  <td width="15%" class="contentbold1">User Updated</td>
								  <td width="14%" class="contentbold1">Date Updated</td>
								  <td width="12%" class="contentbold1">Action</td>
								</tr>                 
									<%
										for(int i=0 ;i<tempVector.size();i++)
										{
											ReleaseVO dispVo = (ReleaseVO)tempVector.elementAt(i);
									%>
											<tr  >	
												<td class=bodyblue > <%= dispVo.getReleaseName()  %> </td>
												<td class=bodyblue > <%= dispVo.getDBName()  %> </td>
												<td class=bodyblue > <%= dispVo.getObjName()  %> </td>
												<%  // System.out.println("display object name >>>>>"+dispVo.getObjName());
												%>
												<td class=bodyblue > <%= dispVo.getObjType()  %> </td>
									<!--		<td class=bodyblue > <%= dispVo.getSqLQuery()  %> </td>  -->
												<td class=bodyblue > <%= dispVo.getUserUpdated()  %> </td>
												<td class=bodyblue align='center'> <%= dispVo.getDateUpdated()  %> </td>
												<td class=bodyblue align='center'><input type=button class=whitebutton name=delbutton value='Delete' 
												onClick=delRow('<%= i %>') ></td>
											</tr>
											
									<%	}
									%>
                      </table>
					  
					  </td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="25%" height="26"><div align="right"><span class="marginscontact">
                              <input type=button  class=whitebutton value=Save onClick="save()"/>
                          </span></div></td>
                          <td width="35%"><div align="center"><span class="marginscontact">
                              <input type=button  class=whitebutton  value="Save &amp; Send" onClick="saveandsend()" />
                          </span>

						  </td>
                          <td width="39%"><div align="right"><span class="contentbold1">Enter Your Email Id [Optional]:</span></div>
						  
						  </td>
                          <td width="27%" valign="middle"><div align="center"><span class="marginscontact">
						  <%	// System.out.println("ContactPersonVector.size():"+ContactPersonVector.size());
									String ContactPersonString="";
									String vectorElementStr="";
									boolean commaflag=false;
									if(ContactPersonVector!=null && ContactPersonVector.size()>0){
										for(int i=0;i<ContactPersonVector.size();i++){
											if(commaflag==true){
												ContactPersonString = ContactPersonString +" , ";
											}
											vectorElementStr = (String)ContactPersonVector.elementAt(i);
											ContactPersonString = ContactPersonString + vectorElementStr;
											commaflag = true;
										}
									
									}
										%>
                             <input type=text name=extraEmail size="40" value='<%=ContactPersonString%>'>
                          </span></div></td>
                        </tr>
                      </table></td>
                    </tr>
                  </table>

				  <% } %>
			<% 
				if("save".equals(act))
				{
					session.removeAttribute("CONTACTPERSONVECTOR");
			%>
					<table width="750">		
					<tr>
					<td class='smalltext'><font color='blue'>Saved Successfully </font></td>
					
					</tr>
					 
					</table>
			<%	}
					%>


				<% 
				if("saveandsend".equals(act) && saveflag==true)
				{
					session.removeAttribute("CONTACTPERSONVECTOR");
			%>
					<table width="750">		
					<tr>
					<td class='smalltext'><font color='blue'>Saved Successfully </font></td>
					
					</tr>
					 
					</table>
			<%	}
					%>

						<% 
				if("saveandsend".equals(act) && sendmailfailflag==true)
				{
					session.removeAttribute("CONTACTPERSONVECTOR");
			%>
					<table width="750">		
					<tr>
					<td class='smalltext'><font color='red'>Could not connect to SMTP host. Sending mail failed !</font></td>
					
					</tr>
					 
					</table>
			<%	}
				if("saveandsend".equals(act) && sendmailfailflag==false)
				{  	
					session.removeAttribute("CONTACTPERSONVECTOR");

					%>
						<table width="750">		
					<tr>
					<td class='smalltext'><font color='blue'>Mail Sent Successfully for added Objects</font></td>
					
					</tr>
					 
					</table>

			<%  } %>
                    <br />
                      <br />
                      <br />
                    <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br />
                      <br /></td>
                </tr>
                
            </table></td>
          </tr>
          <tr>
            <td height="19" colspan="2" valign="top" bgcolor="#CCCCCC"><span class="contentwhitesatheesh">&copy;2010 Joju's Software. All rights reserved.</span></td>
          </tr>
      </table></td>
    </tr>
  </table>
</center>
</form>
</body>
</html>
<% }
}
catch(Exception e) {
				e.printStackTrace();
		}

		%>
